﻿//-----------------------------------------------------------------------
// <copyright file="O365001 - CheckNameSpaces.cs" company="Kimmo Forss">
// </copyright>
// <summary>The class in this file implements the UsingForbiddenNamespaces class</summary>
// <website>http://O365fxcoprules.codeplex.com/</website>
//-----------------------------------------------------------------------
namespace O365FxCopRules
{
    using System;
    using System.Linq;
    using Microsoft.FxCop.Sdk;

    /// <summary>
    /// This rule checks if the code is using assemblies that are not allowed in Office 365
    /// </summary>
    public class UsingForbiddenNamespaces : BaseIntrospectionRule
    {
        /// <summary>
        /// aa
        /// </summary>
        /// <param name="name"></param>
        public UsingForbiddenNamespaces(string name) :
            base(name, "O365FxCopRules.O365Rules", typeof(UseForbiddenMethods).Assembly)
        {
        }
        /// <summary>
        /// bb
        /// </summary>
        public UsingForbiddenNamespaces() :
            base("UsingForbiddenNamespaces", "O365FxCopRules.O365Rules", typeof(UsingForbiddenNamespaces).Assembly)
        {
        }

        public override TargetVisibilities TargetVisibility
        {
            get
            {
                return TargetVisibilities.All;
            }
        }

        public override void BeforeAnalysis()
        {
            // Do once-per-thread initialization.
        }

        public override void AfterAnalysis()
        {
            // Do once-per-thread cleanup. Rarely needed.
        }
        public override ProblemCollection Check(ModuleNode module)
        {
            foreach (AssemblyReference ar in module.AssemblyReferences)
            {
                switch (ar.Name)
                {
                    case "Microsoft.AnalysisServices":
                    case "Microsoft.BusinessData":   
                    case "Microsoft.Office.Excel.Server.Udf":
                    case "Microsoft.Office.SecureStoreService":
                    case "Microsoft.Office.SecureStoreService.Server.Security":
                    case "Microsoft.Office.Server":    
                    case "Microsoft.Office.Server.Diagnostics":      
                    case "Microsoft.Office.Server.Search":
                    case "Microsoft.Office.Server.UserProfiles":
                    case "Microsoft.SharePoint.Portal":           
                    case "Microsoft.SharePoint.Publishing": 
                    case "Microsoft.SharePoint.Search":         
                    case "Microsoft.SharePoint.Search.Extended.Administration.Common":
                    case "Microsoft.SharePoint.Search.Extended.Administration.dll":
                    case "Microsoft.SharePoint.Search.Extended.Administration.ResourceStorage.dll":
                    case "Microsoft.SharePoint.SubsetProxy.dll":
                    case "Microsoft.SqlServer":
                    case "Microsoft.Win32":
                    case "System.Data.Sql":
                    case "System.Data.SqlClient":
                    case "System.Data.SqlTypes":
                    case "System.IO.Pipes":
                    case "System.IO.Ports":
                    case "System.Runtime.Remoting":
                        {
                            Problem p = new Problem(this.GetNamedResolution("Namespace",ar.Name));
                            this.Problems.Add(p);
                            break;
                 
                        }
                }


            }
            return this.Problems;
        }
        public override ProblemCollection Check(string namespaceName, TypeNodeCollection types)
        {
            return base.Check(namespaceName, types);
        }

        public override void VisitAssignmentStatement(AssignmentStatement assignment)
        {
            // Process assignment statement. Add to this.Problems if problems are found.

            // Uncomment the following if you need to recurse deeper (for example, to the Expression level).
             base.VisitAssignmentStatement(assignment);
        }

    }
}